param ( $CmdletName = "" , $ProjectName = "",$URI="http://www.snapins.com/api/cmdlet.asmx")
# /////////////////////////////
# ///// Usage function
# /////////////////////////////
if (! $CmdletName  -or ! $ProjectName ) 
{
    write-Host "Missing Cmdlet Name and/or ProjectName"
    Write-Host "Usage"
    Write-Host "Import-PsSpecCmdletFromCode.ps1 CmdletName ProjectName"
    Write-Host "Example: Import-PsSpecCmdletFromCode.ps1 Get-MailBox Exchange12"
    return 
}

write-host "Updating Cmdlet: $CmdletName in Project: $ProjectName"

#////////////////////////////////////////////
#////////// Function to do XML encoding
#////////// It returns a string
#////////////////////////////////////////////
function XMLEncode ([string]$a)
{
    $a=$a.replace("'","''")
    $a

} #// end XMLEncode Function

function TrimString ([String] $str, [int] $length)
{
	if ($str.Length -gt $length)
		{
			$str = "{" + $str.Substring(0,$length-5) + "}..."
		}	
	$str
}

function Merge ($Texts)
{
	$StringText = $null
	foreach ($Text in $Texts)
		{
			if ($StringText -eq $null)
				{$StringText = $String}
			else
				{$StringText = ", " + $String}
		}
	$StringText
}


## New-GenericObject.ps1 
## Creates an object of a generic type: 
## 
## Usage: 
## 
##   # Simple generic collection 
##   $list = New-GenericObject System.Collections.ObjectModel.Collection System.Int32 
## 
##   # Generic dictionary with two types 
##   New-GenericObject System.Collections.Generic.Dictionary System.String,System.Int32 
## 
##   # Generic list as the second type to a generic dictionary 
##   $secondType = New-GenericObject System.Collections.Generic.List Int32 
##   New-GenericObject System.Collections.Generic.Dictionary System.String,$secondType.GetType() 
## 
##   # Generic type with a non-default constructor 
##   New-GenericObject System.Collections.Generic.LinkedListNode System.Int32 10 
##
function New-GenericObject ( 
    [string] $typeName = $(throw "Please specify a generic type name"), 
    [string[]] $typeParameters = $(throw "Please specify the type parameters"), 
    [object[]] $constructorParameters 
    )
{
 ## Create the generic type name 
$genericTypeName = $typeName + '`' + $typeParameters.Count 
$genericType = [Type] $genericTypeName 

if(-not $genericType) 
{ 
    throw "Could not find generic type $genericTypeName" 
} 

## Bind the type arguments to it 
[type[]] $typedParameters = $typeParameters 
$closedType = $genericType.MakeGenericType($typedParameters) 
if(-not $closedType) 
{ 
    throw "Could not make closed type $genericType" 
} 

## Create the closed version of the generic type 
,[Activator]::CreateInstance($closedType, $constructorParameters) 
}


#### Gather Cmdlet info from Get-Command and Get-Help

# check to see if the Cmdlet record already exists.
$CmdletRecord = Get-PsSpecCmdlet -ser $URI -Name $CmdletName -ProjectName $ProjectName -EA SilentlyContinue


### We create the Cmdlet record here if one does not exit.
If (!$CmdletRecord)
{

    # Create the Cmdlet info and the Cmdlet Help info objects.
    $CmdletInfo =  get-command $CmdletName
    $CmdletHelpInfo = get-help $CmdletName -ea SilentlyContinue

    #$verb is Cmdlet verb
    $verb = $CmdletInfo.Verb

    #$noun is Cmdlet noun
    $noun = $CmdletInfo.Noun



    # $Snapin is the Cmdlet Snapin Name
    $Snapin = $CmdletInfo.PSSnapIn.Name   

    # Check if the Cmdlet implements SupportShouldProcess
    $SupportShouldProcess = $CmdletInfo.Definition -match "-confirm"

    # Get the Short and long description of the Cmdlet from the help info
    
    $ShortDescription = TrimString $CmdletHelpInfo.Synopsis 2000
    if ($CmdletHelpInfo -ne $null)
      {
         $LongDescription += $CmdletHelpInfo.description | foreach{$_.Text}
	 $LongDescription = [String] $LongDescription
      }
    if ($ShortDescription -eq $null)
     {
        $ShortDescription = "Not Specified"
      }

    $testNoun = get-PsSpecNoun -ser $uri -ProjectName $ProjectName -Name $noun -ea SilentlyContinue


          $definition = $ShortDescription
	if (($definition -eq $null) -or ($definition.Length -eq 0))
		{
			$definition = "Not Specified"
		}



    if ($testNoun -eq $null)
      {
         New-PsSpecNoun -ser $URI -Name $noun -Definition $definition  -ProjectName $ProjectName | out-null
      }


    if ($LongDescription -eq $null)
     {
        $LongDescription = "Not Specified"
     }

    # Additional Notes information
    if ($CmdletHelpInfo -ne $null)
      {
        $Notes = $CmdletHelpInfo.alertset.alert | foreach {$_.Text}
	$note="";Foreach ($n in $Notes) {$Note = $Note + $n}
	ForEach ($desc in $CmdletHelpInfo.description)
	{
		$HelpLongDesc += $desc.Text
	}
	$HelpShortDesc = $CmdletHelpInfo.Synopsis
	if ($CmdletHelpInfo.returnValues -ne $null)
	{
		$HelpReturnValue = $CmdletHelpInfo.returnValues.ToString()
	}
	if ($CmdletHelpInfo.inputTypes -ne $null)
	{
		$HelpInputType = $CmdletHelpInfo.inputTypes.ToString()
	}
	if ($CmdletHelpInfo.relatedLinks -ne $null)
	{
		$HelpLinks = $CmdletHelpInfo.relatedLinks.navigationLink | Foreach {$_.Linktext }
		$HelpLinkText = Merge $HelpLinks
	}	 
	$Examples = $CmdletHelpInfo.Examples.Example
	$HelpExamples = New-GenericObject System.Collections.ObjectModel.Collection Microsoft.PowerShell.CmdletManagement.PsSpecHelpExample	
ForEach ($Example in $Examples)
		{
			$HelpExample = New-Object -type Microsoft.PowerShell.CmdletManagement.PsSpecHelpExample	
			#Title of the example
			#This is the example command
			# Intor is C:\PS>
			#Help Description.
			if ($Example.remarks.count -gt 0)
			{
				$HelpExample.Description = $Example.remarks[0].Text
				$HelpExample.Output = $Example.remarks[3].Text			
			}
		# We need to place this in the Cmdlet Designer record.
		$HelpExamples.Add($HelpExample)
		}

      }


    # Do add the examples section
    $ExamplesCount=$CmdletHelpInfo.Examples.example.count
    $tempCount=0
    $SpecExample=""
    while ($tempCount -lt $ExamplesCount)
     {
         $SpecExample += $CmdletHelpInfo.examples.example[$tempCount].title + "`r`n"
         $SpecExample += $CmdletHelpInfo.examples.example[$tempCount].Introduction | foreach {$_.text}
         $SpecExample += $CmdletHelpInfo.Examples.example[$tempCount].introduction + $CmdletHelpInfo.examples.example[$tempCount].code + "`r`n"
         $remCount = 0
         while ($remCount -lt $CmdletHelpInfo.examples.example[$tempCount].remarks.count)
           {
              $SpecExample += $CmdletHelpInfo.examples.example[$tempCount].remarks[$remCount].text + "`r`n" 
              $remCount++
           }
         
         $outCount = 0
         while ($outCount -lt $CmdletHelpInfo.examples.example[$tempCount].commandlines.commandLine.count)
           {
              $SpecExample += $CmdletHelpInfo.examples.example[$tempCount].commandlines.commandLine[$outCount].commandText + "`r`n" 
              $outCount++
           }
         
         $tempCount++
         
     }

     $relatedTo = ""
     $tempCount = 0
     while ($tempCount -lt $CmdletHelpInfo.relatedLinks.navigationLink.count)
        {
          if ($relatedTo -eq "")
             {
                $relatedTo = $CmdletHelpInfo.relatedLinks.navigationLink[$tempCount].linktext
             }
           else
             {
                $relatedTo += ", " + $CmdletHelpInfo.relatedLinks.navigationLink[$tempCount].linktext
             }
          $tempCount++
        }
	
    $relatedTo = TrimString $relatedTo 1000
    $OutputType =  $CmdletHelpInfo.returnValues.returnValue.type.name
    $tempCount=0
    while ($tempCount -lt $CmdletHelpInfo.returnValues.returnValue.type.Description.count)
      {
         $OutputTypeDesc += $CmdletHelpInfo.returnValues.returnValue.type.Description[$tempCount].text + "`r`n"
         $tempCount++
      }


    ################ Create a new Cmdlet record in the database with this minimal set of imformation ##########
    New-PsSPecCmdlet -ser $URI -HelpShort:$HelpShortDesc -HelpLong:$HelpLongDesc -HelpExam $HelpExamples -OutputObject:$OutputType -OutputObjectDescription:$OutputTypeDesc  -Verb $Verb -Noun $Noun -relatedto $HelpLinkText -SpecExa $SpecExample -Snapin $Snapin -Project $ProjectName -SupportsShouldProcess:$SupportShouldProcess -Long $LongDescription -Short $ShortDescription -Note $Note  | out-null

###Debug Message
 
}
else  # we know here that the record exists so we are just going to update the record
{
  ### Skip for now. the Set-Cmdlet is not implemented yet.

}
    
### Get Parameter Info and publish them to the Cmdlet record.

#get unique parameter list and exclude ubiquitious ones:
$ParameterSetscount = (get-command $CmdletName).Parametersets.Count 

$parameters =  $(get-command $CmdletName).Parametersets | Foreach {$_}| foreach {$_.Parameters} | where {"WarningAction", "WarningVariable", "Debug","ErrorAction","ErrorVariable", "OutBuffer","OutVariable", "Verbose", "Confirm", "WhatIf" -notcontains $_.Name}
$parameterNames =  $(get-command $CmdletName).Parametersets | Foreach {$_}| foreach {$_.Parameters} | foreach {$_.Name} | where {"WarningAction", "WarningVariable", "Debug","ErrorAction","ErrorVariable", "OutBuffer","OutVariable", "Verbose", "Confirm", "WhatIf" -notcontains $_} | sort | get-unique

## foreach Parameter un parameterNames array list I need to get the help info on it and the validation attributes.
## things to get:
## Globbing (from help)
## Default value (from help)
## Validation attributes (I need to do more here).

$Help = get-help $CmdletName -ea SilentlyContinue
$LinksCount = $Help.relatedLinks.navigationLink.count
$UAShortDescription = $Help.Synopsis
$UAShortDescription = XMLEncode $UAShortDescription
if ($Help -ne $null)
{
  $UADescriptions = $Help.description | foreach {$_.Text}
  $UADescription="";Foreach ($n in $UADescriptions) {$UADescription = $UADescription + $n}
  $UADescription = XMLEncode $UADescription
  $UAPrameters=$Help.Parameters.Parameter
  $UAInputType=$Help.inputTypes.inputType.type.name
  $UAOutputType=$Help.returnValues.returnValue.type.name
}
    


     $parameters=$null
     $parameterName=$null
     $parmeterType=$null
     $parameterName=,""
     $parmeterType=,""
     $parameters =  $(get-command $CmdletName).Parametersets | Foreach {$_}| foreach {$_.Parameters} | where {"WarningAction", "WarningVariable", "Debug","ErrorAction","ErrorVariable", "OutBuffer","OutVariable", "Verbose", "Confirm", "WhatIf" -notcontains $_.Name}
     if ($parameters.count -gt 0 )
       {
         $parameterCounter=0
         while ($parameterCounter -lt $parameters.count)
          {
            $parameterNameCount=0
               $parameterName += $Parameters[$parameterCounter].Name
               $parmeterType += $Parameters[$parameterCounter].ParameterType
               $ParameterExists=get-PsSpeccmdletParameter -Ser $uri -ProjectName $ProjectName -Name $Parameters[$parameterCounter].Name -CmdletName $CmdletName
               if($ParameterExists -eq $null)
                 {
                    Add-PsSpecCmdletParameter -ServiceUri $uri -ProjectName $ProjectName -Name $Parameters[$parameterCounter].Name -CmdletName $CmdletName -Type $Parameters[$parameterCounter].ParameterType
                   # Write-Host Add-PsSpecCmdletParameter -ServiceUri $uri -ProjectName $ProjectName -Name $Parameters[$parameterCounter].Name -CmdletName $CmdletName -Type $Parameters[$parameterCounter].ParameterType
                 }
                
		$ParameterSetNames = $Parameters[$parameterCounter].Attributes | foreach {$_} | select ParameterSetName
                if ($ParameterSetNames.Count -gt 0)
			{
			$AttribCount=0
			while ($AttribCount -lt $ParameterSetNames.count)
				{
					if ($ParameterSetNames[$AttribCount].Parametersetname -ne $null)
						{
							$ParameterSetName = $ParameterSetNames[$AttribCount].Parametersetname
						}
					$AttribCounT++
				} 
			}
		else
			{
				$ParameterSetName = $ParameterSetNames.Parametersetname
			}
                if ($ParameterSetName -eq "__AllParameterSets") {$ParameterSetName=""}
		$Mandatory=$Parameters[$parameterCounter].IsMandatory
		$ValueFromPipeline=$Parameters[$parameterCounter].ValueFromPipeline
		$ValueFromPipelineByPropertyName=$Parameters[$parameterCounter].ValueFromPipelineByPropertyName
		$ValueFromRemainingArguments=$Parameters[$parameterCounter].ValueFromRemainingArguments
		$Position=$Parameters[$parameterCounter].Position
		if ($Position -eq -2147483648) {$Position=$null}
		$ParameterType=$Parameters[$parameterCounter].ParameterType
		$IsDynamic=$Parameters[$parameterCounter].IsDynamic

                $ValidatePattern=$null
                $AllowEmptyString=$false
                $Alias=""
                $AllowEmptyCollection=$false
                $AllowNull=$false
                $Credential=$false
                $LengthAttrib=$null
                $ValidateNotNull=$false
                $ValidateNotNullOrEmpty=$false
                $RangeAttrib=$null,$null
                $ValidatePattern=$null
	        $HelpMessage=$null
        	$HelpMessageBaseName=$null
                $HelpMessageResourceId=$null

                foreach ($attrib in $Parameters[$parameterCounter].Attributes) 
                  {
                    #AllowEmptyCollection
                     if ($attrib.TypeId.Name -eq "AllowEmptyCollectionAttribute")
                      { $AllowEmptyCollection=$true }


		    #Alias Names
                    if ($attrib.TypeId.name -eq "AliasAttribute") 
                      {$Alias = $attrib.aliasNames}


                    #AllowEmptyStringAttribute 
                    if ($attrib.TypeId.Name -eq "AllowEmptyStringAttribute")
                      { $AllowEmptyString=$true }

                    #AllowNullAttribute 
                    if ($attrib.TypeId.Name -eq "AllowNullAttribute")
                      { $AllowNull=$true}

                    #CredentialAttribute
                    if ($attrib.TypeId.Name -eq "CredentialAttribute")
                      { $Credential=$true}

                    #ValidateLengthAttribute
                    if ($attrib.TypeId.Name -eq "ValidateLengthAttribute")
                      { 
                           $Min=$attrib.MinLength
                           $Max=$attrib.MaxLength
                           $LengthAttrib= $Min , $Max
                      }

                    #ValidateNotNullAttribute
                    if ($attrib.TypeId.Name -eq "ValidateNotNullAttribute")
                      { $ValidateNotNull=$true}

                    #ValidateNotNullOrEmptyAttribute
                    if ($attrib.TypeId.Name -eq "ValidateNotNullOrEmptyAttribute")
                      { $ValidateNotNullOrEmpty=$true}

                    #ValidateRangeAttribute
                    if ($attrib.TypeId.Name -eq "ValidateRangeAttribute")
                      { 
                           $Min=$attrib.MinRange
                           $Max=$attrib.MaxRange
                           $RangeAttrib= $Min , $Max
                      }

		    #ValidateSetAttribute
                    if ($attrib.TypeId.name -eq "ValidateSetAttribute") 
                      { $ValidatePattern=$attrib.validValues}

		    #ValidatePatternAttribute
                    $ValidatePattern=""
                    if ($attrib.TypeId.name -eq "ValidatePatternAttribute") 
                      { $ValidatePattern=$attrib.Pattern}
                       

                    #ParameterAttribute
                    if ($attrib.TypeId.Name -eq "ParameterAttribute")
                      { 
			$HelpMessage=$attrib.HelpMessage
        	        $HelpMessageBaseName = $attrib.HelpMessageBaseName
                	$HelpMessageResourceId = $attrib.HelpMessageResourceId
                      }
                     
                  }




                $helpInfo = get-help $CmdletName -ea SilentlyContinue
                
            
                $GetParameter = Get-PsSpecCmdletParameterSetEntry -CmdletName $CmdletName -ParameterName $Parameters[$parameterCounter].Name -ProjectName $ProjectName -ser $uri 
                $GetParameter | Set-PsSPecCmdletParameterSetEntry -ParameterSetName $ParameterSetName -Man $Mandatory -Pos:$Position -ValueFromPipeline $ValueFromPipeline -ValueFromPipelineByProp $ValueFromPipelineByPropertyName -ValueFromRemainingArgu $ValueFromRemainingArguments -HelpMessage $HelpMessage -ser $uri
                Get-PsSpecCmdletParameter -Name $Parameters[$parameterCounter].Name -CmdletName $CmdletName -Project $ProjectName -Serv $URI | Set-PsSpecCmdletParameter -ServiceUri $URI -ValidatePattern $ValidatePattern  -ValidateSet $ValidateSet -ValidateRange $RangeAttrib -ValidateNotNullOrEmpty $ValidateNotNullOrEmpty -ValidateNotNull $ValidateNotNull -AllowNull $AllowNull -Alias $Alias -AllowEmptyCollection $AllowEmptyCollection -AllowEmptyString $AllowEmptyString                


                #ParameterUADescription
                $UAParameterRecord = $UAPrameters | where {$_.Name -eq $Parameters[$parameterCounter].Name}
                if ( $UAParameterRecord -ne $null)
                 {
                    $UAParameterDescriptions = $UAParameterRecord.description | foreach {$_.Text}
		    $UAParameterDescription="";Foreach ($desc in $UAParameterDescriptions) {$UAParameterDescription += $UAParameterDescription + $desc} 	
                    $UAParameterDefaultValue = $UAParameterRecord.defaultValue
                 }
		else 
		{
			$UAParameterDescription = "Not Specified"
		}
                if ($UAParameterRecord.globbing -ne $null)
                  {
                     $Globbing=" -AllowGlobbing $UAParameterRecord.globbing"
                  }
                else
                  {
                     $Globbing=$null
                  }

                $TypeLength = $ParameterToAdd.ParameterType.Name.Length

                if ($TypeLength -gt 2)
                  {
                      if ($ParameterToAdd.ParameterType.Name[$TypeLength-1] -eq "]" -and $ParameterToAdd.ParameterType.Name[$TypeLength-2] -eq "[" )
                         { $variableLength = $true}
                      else
                         { $variableLength = $false}
                  }
                else
                  {
                       $variableLength = $false
                  }
		if ($UAParameterDescription -eq $null)
		{
			$UAParameterDescription = "Not Specified"
		}

		Get-PsSpecCmdletParameter -Name $Parameters[$parameterCounter].Name -CmdletName $CmdletName -Project $ProjectName -Serv $URI `
		| Set-PsSpecCmdletParameter -Ser $URI -Description "$UAParameterDescription" -HelpDescription "$UAParameterDescription" 
		$UAParameterDescription=$null
           $parameterCounter++
          }

       }
	elseif (($parameters.count -eq $null) -and ($parameters -ne $null))
	  {
		$parameterNameCount=0

               $parameterName += $Parameters.Name
               $parmeterType += $Parameters.ParameterType
               $ParameterExists=get-PsSpeccmdletParameter -Ser $uri -ProjectName $ProjectName -Name $Parameters.Name -CmdletName $CmdletName
               if($ParameterExists -eq $null)
                 {
                    Add-PsSpecCmdletParameter -ServiceUri $uri -ProjectName $ProjectName -Name $Parameters.Name -CmdletName $CmdletName -Type $Parameters.ParameterType
                 }
                
		$ParameterSetNames = $Parameters.Attributes | foreach {$_} | select ParameterSetName
                if ($ParameterSetNames.Count -gt 0)
			{
			$AttribCount=0
			while ($AttribCount -lt $ParameterSetNames.count)
				{
					if ($ParameterSetNames[$AttribCount].Parametersetname -ne $null)
						{
							$ParameterSetName = $ParameterSetNames[$AttribCount].Parametersetname
						}
					$AttribCounT++
				} 
			}
		else
			{
				$ParameterSetName = $ParameterSetNames.Parametersetname
			}
                if ($ParameterSetName -eq "__AllParameterSets") {$ParameterSetName=""}
		$Mandatory=$Parameters.IsMandatory
		$ValueFromPipeline=$Parameters.ValueFromPipeline
		$ValueFromPipelineByPropertyName=$Parameters.ValueFromPipelineByPropertyName
		$ValueFromRemainingArguments=$Parameters.ValueFromRemainingArguments
		$Position=$Parameters.Position
		if ($Position -eq -2147483648) {$Position=$null}
		$ParameterType=$Parameters.ParameterType
		$IsDynamic=$Parameters.IsDynamic

                $ValidatePattern=$null
                $AllowEmptyString=$false
                $Alias=""
                $AllowEmptyCollection=$false
                $AllowNull=$false
                $Credential=$false
                $LengthAttrib=$null
                $ValidateNotNull=$false
                $ValidateNotNullOrEmpty=$false
                $RangeAttrib=$null,$null
                $ValidatePattern=$null
	        $HelpMessage=$null
        	$HelpMessageBaseName=$null
                $HelpMessageResourceId=$null

                foreach ($attrib in $Parameters.Attributes) 
                  {
                    #AllowEmptyCollection
                     if ($attrib.TypeId.Name -eq "AllowEmptyCollectionAttribute")
                      { $AllowEmptyCollection=$true }


		    #Alias Names
                    if ($attrib.TypeId.name -eq "AliasAttribute") 
                      {$Alias = $attrib.aliasNames}


                    #AllowEmptyStringAttribute 
                    if ($attrib.TypeId.Name -eq "AllowEmptyStringAttribute")
                      { $AllowEmptyString=$true }

                    #AllowNullAttribute 
                    if ($attrib.TypeId.Name -eq "AllowNullAttribute")
                      { $AllowNull=$true}

                    #CredentialAttribute
                    if ($attrib.TypeId.Name -eq "CredentialAttribute")
                      { $Credential=$true}

                    #ValidateLengthAttribute
                    if ($attrib.TypeId.Name -eq "ValidateLengthAttribute")
                      { 
                           $Min=$attrib.MinLength
                           $Max=$attrib.MaxLength
                           $LengthAttrib= $Min , $Max
                      }

                    #ValidateNotNullAttribute
                    if ($attrib.TypeId.Name -eq "ValidateNotNullAttribute")
                      { $ValidateNotNull=$true}

                    #ValidateNotNullOrEmptyAttribute
                    if ($attrib.TypeId.Name -eq "ValidateNotNullOrEmptyAttribute")
                      { $ValidateNotNullOrEmpty=$true}

                    #ValidateRangeAttribute
                    if ($attrib.TypeId.Name -eq "ValidateRangeAttribute")
                      { 
                           $Min=$attrib.MinRange
                           $Max=$attrib.MaxRange
                           $RangeAttrib= $Min , $Max
                      }

		    #ValidateSetAttribute
                    if ($attrib.TypeId.name -eq "ValidateSetAttribute") 
                      { $ValidatePattern=$attrib.validValues}

		    #ValidatePatternAttribute
                    $ValidatePattern=""
                    if ($attrib.TypeId.name -eq "ValidatePatternAttribute") 
                      { $ValidatePattern=$attrib.Pattern}
                       

                    #ParameterAttribute
                    if ($attrib.TypeId.Name -eq "ParameterAttribute")
                      { 
			$HelpMessage=$attrib.HelpMessage
        	        $HelpMessageBaseName = $attrib.HelpMessageBaseName
                	$HelpMessageResourceId = $attrib.HelpMessageResourceId
                      }
                     
                  }




                $helpInfo = get-help $CmdletName -ea SilentlyContinue
                
            
                $GetParameter = Get-PsSpecCmdletParameterSetEntry -CmdletName $CmdletName -ParameterName $Parameters.Name -ProjectName $ProjectName -ser $uri 
                $GetParameter | Set-PsSPecCmdletParameterSetEntry -ParameterSetName $ParameterSetName -Man $Mandatory -Pos:$Position -ValueFromPipeline $ValueFromPipeline -ValueFromPipelineByProp $ValueFromPipelineByPropertyName -ValueFromRemainingArgu $ValueFromRemainingArguments -HelpMessage $HelpMessage -ser $uri
                Get-PsSpecCmdletParameter -Name $Parameters.Name -CmdletName $CmdletName -Project $ProjectName -Serv $URI | Set-PsSpecCmdletParameter -ServiceUri $URI -ValidatePattern $ValidatePattern  -ValidateSet $ValidateSet -ValidateRange $RangeAttrib -ValidateNotNullOrEmpty $ValidateNotNullOrEmpty -ValidateNotNull $ValidateNotNull -AllowNull $AllowNull -Alias $Alias -AllowEmptyCollection $AllowEmptyCollection -AllowEmptyString $AllowEmptyString                


                #ParameterUADescription
                $UAParameterRecord = $UAPrameters | where {$_.Name -eq $Parameters.Name}
                if ( $UAParameterRecord -ne $null)
                 {
                    $UAParameterDescriptions = $UAParameterRecord.description | foreach {$_.Text}
		    $UAParameterDescription="";Foreach ($desc in $UAParameterDescriptions) {$UAParameterDescription += $UAParameterDescription + $desc} 
                    $UAParameterDefaultValue = $UAParameterRecord.defaultValue
                 }
		else 
		{
			$UAParameterDescription = "Not Specified"
		}
                if ($UAParameterRecord.globbing -ne $null)
                  {
                     $Globbing=" -AllowGlobbing $UAParameterRecord.globbing"
                  }
                else
                  {
                     $Globbing=$null
                  }


                $TypeLength = $ParameterToAdd.ParameterType.Name.Length

                if ($TypeLength -gt 2)
                  {
                      if ($ParameterToAdd.ParameterType.Name[$TypeLength-1] -eq "]" -and $ParameterToAdd.ParameterType.Name[$TypeLength-2] -eq "[" )
                         { $variableLength = $true}
                      else
                         { $variableLength = $false}
                  }
                else
                  {
                       $variableLength = $false
                  }
		if ($UAParameterDescription -eq $null)
		{
			$UAParameterDescription = "Not Specified"
		}

		Get-PsSpecCmdletParameter -Name $Parameters.Name -CmdletName $CmdletName -Project $ProjectName -Serv $URI `
		| Set-PsSpecCmdletParameter -Ser $URI -Description "$UAParameterDescription" -HelpDescription "$UAParameterDescription" 
		$UAParameterDescription=$null

	  }

